package com.oracle.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.compents.PageResult;
import com.oracle.mapper.PhCartMapper;
import com.oracle.pojo.PhCart;
import com.oracle.pojo.PhCartExample;
import com.oracle.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class CartServiceImpl implements CartService {

	@Autowired
	private PhCartMapper cartMapper;

	/**
	 * 查询全部
	 */
	@Override
	public List<PhCart> findAll() {
		return cartMapper.selecPhyExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		Page<PhCart> page=   (Page<PhCart>) cartMapper.selecPhyExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(PhCart cart) {
		cartMapper.insert(cart);
	}


	/**
	 * 修改
	 */
	@Override
	public void update(PhCart cart){
		cartMapper.updateByPrimaryKey(cart);
	}

	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public PhCart findOne(Long id){
		return cartMapper.selecPhyPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Long[] ids) {
		for(Long id:ids){
			cartMapper.deleteByPrimaryKey(id);
		}
	}


		@Override
	public PageResult findPage(PhCart cart, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);

		PhCartExample example=new PhCartExample();
		PhCartExample.Criteria criteria = example.createCriteria();

		if(cart!=null){

		}

		Page<PhCart> page= (Page<PhCart>)cartMapper.selecPhyExample(example);
		return new PageResult(page.getTotal(), page.getResult());
	}

}
